﻿using G.Model;
using G.Runtime;

namespace G.Runtime
{
    public class GameEvent : System.IDisposable
    {
        public delegate void InvokeHandler(GameSpace pGame);
        public delegate void GameEventHandler(GameEvent pGameEvent);
        public event InvokeHandler InvokeEvent;
        public event GameEventHandler DisposableEvent;

        private GameEventDef _GameEventDef;
        private GameSpace _Game;

        public GameEvent(GameSpace pGame, GameEventDef pGameEventDef) 
        {
            _Game = pGame;
            _GameEventDef = pGameEventDef;
        }

        public GameEventDef Def
        {
            get { return _GameEventDef; }
        }

        public void Dispose()
        {
            if (DisposableEvent != null)
            {
                DisposableEvent(this);
            }
        }

        public void FireInvoke()
        {
            if (InvokeEvent != null)
            {
                InvokeEvent(_Game);
            }
        }

        public override string ToString()
        {
            return _GameEventDef.ToString();
        }


    }
}
